﻿<template>
  <div class="entity-view">
    <EntityManager :entity-config="entityConfig" />
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import EntityManager from '@/components/EntityManager.vue'
import { getEntityConfig } from '@/config/entities'

const route = useRoute()
const router = useRouter()

const entityConfig = computed(() => {
  const tableName = route.params.tableName as string
  const config = getEntityConfig(tableName)

  if (!config) {
    ElMessage.warning(`未找到表 ${tableName} 的配置`)
    router.replace({ name: 'Dashboard' })
    return {
      name: tableName,
      tableName,
      displayName: tableName,
      apiPath: `/api/${tableName}`,
      fields: [],
      hasCompositePrimaryKey: false
    } as any
  }

  return config
})
</script>

<style scoped>
.entity-view {
  padding: 24px;
}
</style>
